﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using MathExpression;

namespace SimplexSolver
{
    public class LPTask : ILPTask
    {
        public ISolution X { get; private set; }

        public int Size { get; private set; }

        public ReadOnlyCollection<Restriction> Restrictions
        {
            get { return _restrictions.AsReadOnly(); }
        }

        public TargetFunction Target { get; private set; }

        private readonly List<Restriction> _restrictions;

        public LPTask(int varCount)
        {
            Size = varCount;
            _restrictions = new List<Restriction>();
        }

        public void AddRestriction(Restriction restriction)
        {
            if (!_restrictions.Contains(restriction))
            {
                _restrictions.Add(restriction);
            }
        }

        public void SetTargetFunction(TargetFunction targetFunction)
        {
            if (targetFunction.Coefs.Count != Size)
            {
                throw new Exception("Target funtion coefs count not equal LPTask size");
            }
            Target = targetFunction;
        }

        public void SetSolution(ISolution solution)
        {
            X = solution;
        }
    }
}